package com.ucode.hrm.service.impl;

import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.util.ObjUtil;
import com.ucode.hrm.mapper.HrmEmployeeMapper;
import com.ucode.hrm.mapper.HrmResignationApplyMapper;
import com.ucode.hrm.service.HrmResignationApplyService;
import com.ucode.model.hrm.HrmResignationApply;
import com.ucode.tool.base.enums.CommonAuditStatusEnum;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class HrmResignationApplyServiceImpl implements HrmResignationApplyService {

    @Resource
    private HrmResignationApplyMapper resignationApplyMapper;
    @Resource
    private HrmEmployeeMapper employeeMapper;

    @Override
    public HrmResignationApplyMapper initMapper() {
        return resignationApplyMapper;
    }

    @Override
    public void audit(Long id, Integer auditStatus, Long processorId, String processRemark) {
        HrmResignationApply bean = resignationApplyMapper.selectByPrimaryKey(id);

        if(bean.getDeltag() || !ObjUtil.equals(bean.getAuditStatus(), CommonAuditStatusEnum.SUBMIT_REVIEW.getCode())) {
            return;
        }

        HrmResignationApply updateBean = new HrmResignationApply();
        updateBean.setId(id);
        updateBean.setAuditStatus(auditStatus);
        updateBean.setProcessRemark(processRemark);
        updateBean.setProcessorId(processorId);
        updateBean.setProcessTime(LocalDateTimeUtil.now());

        resignationApplyMapper.update(updateBean);
    }

}
